// 
//  MathQuestion.cpp
//  LoginSecurity
//  
//  Created by Ryan Latta on 2008-12-03.
//  Copyright 2008 Ryan Latta. All rights reserved.
// 
//  TODO Make the arithmatic recursively generated so it is more complicated.

#ifndef MATHQUESTION_CPP_7F8DLH7T
#define MATHQUESTION_CPP_7F8DLH7T

#include "Security.h"

#endif /* end of include guard: MATHQUESTION_CPP_7F8DLH7T */




// TODO Fix this crappy global array.
char MathQuestion::operations[] = "+-*/";

MathQuestion::~MathQuestion() {}
 

MathQuestion::MathQuestion(int low, int high) {
  random->newSeed();
  s.precision(2);
  l = low;
  h = high;
  
}
void MathQuestion::generateQuestion() {
  fNumber1 = random->getRandom(l, h, 1);
  fNumber2 = random->getRandom(l, h, 1);

  randomOperation = random->getRandom(0,4);
  s << fNumber1 << " " << operations[randomOperation] << " " << fNumber2 << " = ";
  Question::question = s.str();
  s.str("");
}

void MathQuestion::generateAnswer() {
  float fAnswer;
  switch(randomOperation) {
    case 0:
    fAnswer = fNumber1 + fNumber2;
    break;
    case 1:
    fAnswer = fNumber1 - fNumber2; 
    break;
    case 2:
    fAnswer = fNumber1 * fNumber2;
    break;
    case 3:
    fAnswer = fNumber1 / fNumber2;
    break;
    default:
    //Everyone needs some more practice multiplying.
    fAnswer = fNumber1 * fNumber2;
    break;
  }
  s << fAnswer;
  Question::answer = s.str();
  s.str("");
}

